package com.mav01.mrpbackend.mapper;

import com.mav01.mrpbackend.pojo.MrpPlan;
import com.mav01.mrpbackend.pojo.MrpResult;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MrpPlanMapper {

    // 插入MRP计划
    @Insert("INSERT INTO mrp_plan(plan_name, product_material_no, product_name, production_quantity, delivery_date) " +
            "VALUES(#{planName}, #{productMaterialNo}, #{productName}, #{productionQuantity}, #{deliveryDate})")
    @Options(useGeneratedKeys = true, keyProperty = "planId")
    int insertMrpPlan(MrpPlan mrpPlan);

    // 插入MRP结果
    int batchInsertMrpResults(@Param("list") List<MrpResult> results);

    // 根据计划ID查询计划
    @Select("SELECT * FROM mrp_plan WHERE plan_id = #{planId}")
    MrpPlan selectMrpPlanById(Long planId);

    // 根据计划ID查询结果
    @Select("SELECT * FROM mrp_result WHERE plan_id = #{planId} ORDER BY level, material_no")
    List<MrpResult> selectMrpResultsByPlanId(Long planId);
}